package com.videoaggre.zcl.ui.fragment.enterdesk

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.videoaggre.zcl.R
import com.videoaggre.zcl.bean.EnterdeskClassify
import com.videoaggre.zcl.common.ENTERDESK_CLASSIFY
import com.videoaggre.zcl.common.dp
import com.videoaggre.zcl.common.startKtxActivity
import com.videoaggre.zcl.databinding.EnterdeskItemResolutionBinding
import com.videoaggre.zcl.ui.activity.wallpaper.enterdesk.EnterdeskClassifyImageActivity
import com.videoaggre.zcl.ui.adapter.BaseRecyclerAdapter
import com.videoaggre.zcl.ui.adapter.BaseViewHolder
import com.videoaggre.zcl.ui.fragment.BaseFragment
import kotlinx.android.synthetic.main.enterdesk_fragment_resolution.*

class EnterdeskResolutionFragtment : BaseFragment(R.layout.enterdesk_fragment_resolution) {
    private val mEnterdeskResolutionAdapter = EnterdeskResolutionAdapter()
    override fun initView(rootView: View?, savedInstanceState: Bundle?) {
        val displayMetrics = requireContext().resources.displayMetrics
        tvCurrentResolution.text = "当前分辨率：${displayMetrics.widthPixels}X${displayMetrics.heightPixels}"
        recyclerView.adapter = mEnterdeskResolutionAdapter
        recyclerView.layoutManager = GridLayoutManager(context, 2)
        recyclerView.setPadding(3.dp, (-3).dp, 3.dp, 3.dp)
    }

    override fun initData(rootView: View?, savedInstanceState: Bundle?) {
        mEnterdeskResolutionAdapter.datas = mutableListOf<EnterdeskClassify>().apply {
            add(EnterdeskClassify(name = "480x800", path = "480x800"))
            add(EnterdeskClassify(name = "480x854", path = "480x854"))
            add(EnterdeskClassify(name = "640x960", path = "640x960"))
            add(EnterdeskClassify(name = "540x960", path = "540x960"))
            add(EnterdeskClassify(name = "640x1136", path = "640x1136"))
            add(EnterdeskClassify(name = "720x1280", path = "720x1280"))
            add(EnterdeskClassify(name = "750x1334", path = "750x1334"))
            add(EnterdeskClassify(name = "800x1280", path = "800x1280"))
            add(EnterdeskClassify(name = "1080x1920", path = "1080x1920"))
            add(EnterdeskClassify(name = "1440x2960", path = "1440x2960"))
            add(EnterdeskClassify(name = "1440x2560", path = "1440x2560"))
        }
        mEnterdeskResolutionAdapter.notifyDataSetChanged()
    }

    class EnterdeskResolutionAdapter : BaseRecyclerAdapter<BaseViewHolder<EnterdeskItemResolutionBinding>, EnterdeskClassify>() {
        override fun onCreateViewHolder(parent: ViewGroup, p1: Int) = BaseViewHolder(EnterdeskItemResolutionBinding.inflate(getLayoutInflate(parent.context), parent, false))
        override fun onBindViewHolder(holder: BaseViewHolder<EnterdeskItemResolutionBinding>, bean: EnterdeskClassify, position: Int) {
            holder.mViewBinding.apply {
                bean.apply {
                    tvClassifyName.text = name
                    setViewClick(position, root)
                }
            }
        }

        override fun subOnClickAdapter(v: View, position: Int) {
            v.context.startKtxActivity<EnterdeskClassifyImageActivity>(value = ENTERDESK_CLASSIFY to getItem(position))
        }
    }
}